/*
appmain.js  1.0
specific javascript function for the GSF MainMenu page ONLY!
*/

var CurSearchPage='';
var SearchPage='';
var g_Popup=[];
var g_PUn=0;
var g_Alert=[];
var g_Aln=0;
var g_MsgBox;
var p_ViewWidth=900;
var p_ViewHeight=700;
var p_MenuWidth=225;
var p_msTillPopup;
var p_sessionWarningWindow;
var p_SessModalInterval;
var p_countDowncontainer=0;
var p_currentSeconds=0;
var g_jsErrorTxt='';
var g_jsErrorType;
var ele_ListBar;
var ele_MenuDiv;
var ele_MainContent;
var mnu_hidden=true;
var mnu_pinned=true;
var mnu_numGroups=15;
var pressed_keys="";
var g_jsSearchButton;
var g_iSTimeOut;
var g_jsPageTitle="GSF Main";
var p_SessionTimeout=gup("timeout")?gup("timeout"):58;
if(typeof window.innerWidth!='undefined')
{
HTMLElement.prototype.click=function(){
var evt=document.createEvent('MouseEvents');
evt.initMouseEvent('click',true,true,document.defaultView,1,0,0,0,0,false,false,false,false,0,null);
this.dispatchEvent(evt);
};
}
function ClearMem(){
ele_ListBar=null;
ele_MenuDiv=null;
g_jsSearchButton=null;
g_iSTimeOut=null;
}
function ShowMenu(){
if(!really_over(_gE("lh-col"))){return;}
var theImage=_gE('theDockPanelImage');
document.body.scrollIntoView(true);
if(mnu_hidden&&!mnu_pinned){
var theMainMenuTitle=_gE('theMainMenuTitle');
theMainMenuTitle.innerText=g_jsPageTitle;
var theMenuTable=_gE('MenuTable');
theMenuTable.style.backgroundImage="url(/images/onyxBar.gif)";
theMenuTable.style.backgroundRepeat="repeat-x";
p_MenuWidth=225;
ele_MenuDiv.style.width=p_MenuWidth+'px';
ele_ListBar.Element.style.display='';
theImage.src='./images/unpinned.gif';
ele_MainContent.style.width=(p_ViewWidth-p_MenuWidth)+"px";
ele_MainContent.style.left=ele_MenuDiv.style.width;
mnu_hidden=false;
}
else
{
theImage.src='./images/pinned.gif';
}
}
function HideMenu(){
if(!really_out(_gE("lh-col"))){return;}
document.body.scrollIntoView(true);
if(!mnu_hidden&&!mnu_pinned)
{
var theMainMenuTitle=_gE('theMainMenuTitle');
var theImage=_gE('theDockPanelImage');
var theMenuTable=_gE('MenuTable');
p_MenuWidth=15;
ele_MenuDiv.style.width=p_MenuWidth+'px';
theMenuTable.style.backgroundImage="url(/images/toggle_bg_hor.gif)";
theMenuTable.style.backgroundRepeat="repeat-y";
ele_ListBar.Element.style.display='none';
theMainMenuTitle.innerText="  M A I N  -  M E N U";
theImage.src='./images/trans.gif';
ele_MainContent.style.width=(p_ViewWidth-p_MenuWidth)+"px";
ele_MainContent.style.left=p_MenuWidth;
mnu_hidden=true;
}
}
function pinTheMenu(){
mnu_pinned=!mnu_pinned;
var theImage=_gE('theDockPanelImage');
if(mnu_pinned){theImage.src='./images/pinned.gif';}
else{theImage.src='./images/unpinned.gif';}
}
function onResizeEnd()
{
ele_ListBar=iglbar_getListbarById('wb');
ele_MenuDiv=_gE('lh-col');
document.body.scrollIntoView(true);
p_ViewHeight=getViewPortHeight();
p_ViewWidth=getViewPortWidth();
document.body.style.height=p_ViewHeight+"px";
var GroupHeight=xHeight(ele_ListBar.SelectedGroup.Element[0].id);
mnu_numGroups=ele_ListBar.Groups.length;
if(typeof window.innerWidth!='undefined')
{
ele_ListBar.Element.style.height=p_ViewHeight-94+"px";
}
else{
var tHeight=p_ViewHeight-(mnu_numGroups*GroupHeight)-99;
if(tHeight<5){
ele_ListBar.Element.style.height=(p_ViewHeight-20)+"px";
}
else{
ele_ListBar.Element.style.height=tHeight+"px";
}
}
var theMenuTable=_gE('MenuTable');
var theHeader=_gE('hdr');
ele_MainContent.style.height=p_ViewHeight-68+"px";
ele_MenuDiv.style.height=ele_MainContent.style.height;
theMenuTable.style.height=ele_MainContent.style.height;
theHeader.style.width=p_ViewWidth;
ele_MainContent.style.width=p_ViewWidth-p_MenuWidth+"px";
ele_MainContent.style.left=p_MenuWidth+"px";
}
function Button1_onclick(){
if(Button1.value=="Hide Menu")
{
top.frameset.cols="1,*";
Button1.value="Show Menu";
return;
}
if(Button1.value=="Show Menu")
{
top.frameset.cols="25%,*";
Button1.value="Hide Menu";
return;
}
}
function keepMeAlive(imgName){
myImg=_gE(imgName);
if(myImg){myImg.src=myImg.src.replace(/\?.*$/,'?'+Math.random());}
}
function RefreshModule(WarpPanelName)
{
ig_getWebControlById(WarpPanelName).refresh();
}
function RedirectContent(strURL)
{
ele_MainContent.src=strURL;
}
function OpenUnitTest(strTask,strOpId,strOpNum,strMeasurementTable)
{
var strURL="/Views/UnitTestInspection/ScanIn.aspx?Tsk="+strTask+"&OpId="+strOpId+"&OpNum="+strOpNum+"&MTable="+strMeasurementTable;
RedirectContent(strURL);
}
function RefreshContent()
{
_gE("ifMainContent").src=_gE("ifMainContent").src;
}
function RefreshContentWarpPanel(warpName)
{
top.frames['ifMainContent'].RefreshWarp(warpName);
}
function OpenSearchDialog(strSrchPage){
var sTitle;
if(strSrchPage.length>1){
if(strSrchPage=="UnitSetup"){sTitle="Unit Setup Search";}
else{
sTitle="Product Setup Search";
}
g_Popup[g_PUn]=new ModalDlg({id:'',
'width':p_ViewWidth-80,'height':p_ViewHeight-60,
'loc':locTypes.CEN,'type':contentTypes.iframe,'modal':true,
'title':sTitle,'URL':'/Views/'+strSrchPage+'/NewSearch.aspx'
});
g_Popup[g_PUn].show();
g_PUn+=1;
}
else{
alert("No Search defined for current page.");
}
}
function OpenSourceDialog(myLocation)
{
var protocol=myLocation.protocol;
var path=myLocation.pathname;
var file=path.substring(path.lastIndexOf('/')+1);
if(file.length>1){showModalDlg('/admin/PublishCode/SrcViewer/SrcView.aspx?path='+path+'&file='+file,null,p_ViewWidth-80,p_ViewHeight-60,"CEN",true,false);}
else{alert("Invalid filepath: "+file);}
}
function openDialog(url,returnFunc,width,height,strTitle,retFocus){
if(strTitle==undefined)
{
strTitle='Dialog Window';
}
var popup=new ModalDlg({id:'',
'width':width,'height':height,
'loc':locTypes.CEN,'type':contentTypes.iframe,'modal':true,
'title':'Dialog Window','URL':url
});
popup.show();
}
function openModalDialog(idDlg,url,width,height,checkcurrent,strTitle,Loc,returnFunc,retFocus){
if(idDlg==null)idDlg='';
if(Loc==null)Loc=locTypes.N;
g_Popup[g_PUn]=new ModalDlg({
'id':idDlg,'returnFunc':returnFunc,'returnFocusID':retFocus,
'width':width,'height':height,
'loc':Loc,'type':contentTypes.iframe,'modal':true,
'title':strTitle,'URL':url
});
g_Popup[g_PUn].show();
g_PUn+=1;
}
function CloseAllErrors(){
for(var i=g_Aln;i>=0;i--){
hideError(i);
}
g_Aln=0;
}
function hideError(iter){
if(g_Aln>0){
if(g_Alert[g_Aln-1]!=null){g_Alert[g_Aln-1].hide(contentTypes.alert);}
g_Alert[g_Aln-1]=null;
g_Aln-=1;
g_Alert.length=g_Aln;
}
}
function closeModalDialog(dlgId,dlgIdRefresh){
if(dlgId==null){
if(g_PUn>0){
if(g_Popup[g_PUn-1]!=null){g_Popup[g_PUn-1].hide(contentTypes.iframe);}
g_Popup[g_PUn-1]=null;
g_PUn-=1;
g_Popup.length=g_PUn;
}
}
else{
for(var i=0;i<=g_PUn;i++){
if(g_Popup[i].id==dlgId){
if(g_Popup[i]!=null){g_Popup[i].hide(contentTypes.iframe);}
g_Popup[i]=null;
g_PUn-=1;
}
}
}
}
function MaintainChildFocus()
{
try
{
if(top.p_sessionWarningWindow)
{
if(top.p_sessionWarningWindow.closed)
{window.clearInterval(p_SessModalInterval);}
else
{top.p_sessionWarningWindow.focus();}
}
}catch(e){}
}
function RegisterTimeout(seconds)
{
if(seconds==undefined){seconds=p_SessionTimeout;}
p_msTillPopup=(seconds*60)*1000;
if(g_iSTimeOut!=undefined){clearTimeout(g_iSTimeOut);}
g_iSTimeOut=window.setTimeout('FireWarning()',p_msTillPopup);
}
function HandleFocus()
{
if(top.p_sessionWarningWindow)
{
if(!top.p_sessionWarningWindow.closed)
{top.p_sessionWarningWindow.focus();}
else
{window.top.onfocus="";}
}
return false;
}
function SessionUnload()
{
if(top.p_sessionWarningWindow)
{top.p_sessionWarningWindow.close();}
}
function FireWarning()
{
var leftOffset=(screen.width-578)/2;
var topOffset=(screen.height-185)/2;
window.onfocus=HandleFocus;
window.onunload=SessionUnload;
top.p_sessionWarningWindow=window.open("","warning",'toolbar=0,titlebar=0,scrollbars=0,resizable=0,menubar=0,Height=185,Width=578,top='+topOffset+',left='+leftOffset);
top.p_sessionWarningWindow.focus();
htmlWrite();
p_SessModalInterval=window.setInterval("MaintainChildFocus()",1);
}
function htmlWrite()
{
var head=document.getElementsByTagName("HEAD");
var arrBuf=[];
arrBuf.push("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'>");
arrBuf.push("<HTML><head><title>Session Timeout Warning</title>");
arrBuf.push(head[0].innerHTML);
arrBuf.push("<style>.container {width:100%; height:100%;}</style><script>var timerID = window.setTimeout('ShowLogOffMessage()', 60000);");
arrBuf.push("var hasRefreshed = false;var logOffUrl='/anon/loggedout.htm';var idletimeoutUrl='/anon/loggedout.htm';");
arrBuf.push("function HandleRefresh(){hasRefreshed = true;self.opener.SessionRefresh(); self.close();}");
arrBuf.push("function Exit(){if(!hasRefreshed){ShowLogOffMessage();}}function LoseFocus(){self.focus();}");
arrBuf.push("function ShowLogOffMessage(){SessionHide('NormalView');SessionShow('ExpiredView');hasRefreshed=false; self.opener.top.location=logOffUrl;}");
arrBuf.push("function HandleLogOff(){hasRefreshed=false;self.opener.top.location=logOffUrl; if(self.opener.bolCloseChildren) { self.opener.bolCloseChildren(); }}");
arrBuf.push("function SessionHide(id) { ActivateCountDown('CountDownPanel', 60); document.getElementById(id).style.display = 'none';}");
arrBuf.push("function SessionShow(id) { document.getElementById(id).style.display = ''; }");
arrBuf.push("function ActivateCountDown(strContainerID, initialValue) { p_countDowncontainer = document.getElementById(strContainerID);if (!p_countDowncontainer) {alert('count down error: container does not exist: '+strContainerID+'   make sure html element with this ID exists'); return;}SetCountdownText(initialValue);window.setTimeout('CountDownTick()', 1000);}");
arrBuf.push("function CountDownTick() {if (p_currentSeconds <= 0) {return;} SetCountdownText(p_currentSeconds-1);window.setTimeout('CountDownTick()', 1000);} ");
arrBuf.push("function SetCountdownText(seconds) {p_currentSeconds = seconds; var minutes=parseInt(seconds/60); seconds = (seconds%60);var hours=parseInt(minutes/60);minutes = (minutes%60);var strText = AddZero(hours) + ':' + AddZero(minutes) + ':' + AddZero(seconds); p_countDowncontainer.innerHTML = strText;}");
arrBuf.push("function AddZero(num) { return ((num >= 0)&&(num < 10))?'0'+num:num+'';}");
arrBuf.push("</script><style type=\"text/css\">#CountDownPanel {color: blue; background-color: yellow; font-size: 18px;}</style></head>");
arrBuf.push("<body style='border: solid #5280b1 5px;border-top-width : 25px;' onLoad='javascript:SessionHide(\"ExpiredView\"); return false;' onUnLoad='javascript:Exit();' onblur='javascript:LoseFocus();'>");
arrBuf.push("<table id='NormalView' class='container'>");
arrBuf.push("<tr><td align='center'>Time remaining: <span id='CountDownPanel'></span></td></tr>");
arrBuf.push("<tr><td align='center' class='bodyTextBold'> -- ");
arrBuf.push("Your online session will expire in approximately one minute.<br/>Click \"OK\" to continue your online session or click \"Log Off\"<br/>to end your session now.");
arrBuf.push("</td></tr><tr><td align='center' class='tanButtonRow'>");
arrBuf.push("<input type='button' id='btnOK' value='&nbsp;&nbsp;OK&nbsp;&nbsp;' class='buttonFwd' onClick='javascript:HandleRefresh();'>");
arrBuf.push("<input type='button' id='btnLogOff' value='Log Off' class='buttonFwd' onclick='javascript:window.setTimeout(\"HandleLogOff();\",100);'>");
arrBuf.push("</td></tr></table><table id='ExpiredView' class='container'><tr><td class='spacerH5'>&nbsp;</td></tr><tr>");
arrBuf.push("<td rowspan='3' class=spacerW20>&nbsp;</td><td align='center' class='bodyTextBold'>");
arrBuf.push("<br><img src='/images/clock.gif' alt='clock'  align='absmiddle'>&nbsp;Your online session has expired.<br>");
arrBuf.push("<br><br></td><TD rowspan='3' class=spacerW20>&nbsp;</TD></tr><tr><td><div class='dashes'>&nbsp;</div></td></tr>");
arrBuf.push("<tr><td align='center' class='tanButtonRow'>");
arrBuf.push("<INPUT type='button'  value='&nbsp;&nbsp;OK&nbsp;&nbsp;' class='buttonFwd' onclick='javascript:window.setTimeout(\"HandleLogOff();\",100);'>");
arrBuf.push("</td></tr><tr><td class='spacerH10'>&nbsp;</td></tr></table></body></html>");
top.p_sessionWarningWindow.document.open();
top.p_sessionWarningWindow.document.write(arrBuf.join("\n\r"));
top.p_sessionWarningWindow.document.close();
}
function SessionRefresh(seconds)
{
if(seconds==undefined){seconds=p_SessionTimeout;}
p_msTillPopup=(seconds*60)*1000;
top.window.clearTimeout(g_iSTimeOut);
g_iSTimeOut=top.window.setTimeout('FireWarning()',p_msTillPopup);
keepMeAlive('keepMeAlive');
}
function DisplayError(retFunc,sTask,retFocus){
if(sTask==null){sTask="Unknown";}
g_Alert[g_Aln]=new ModalDlg({
'width':300,'height':700,'returnFunc':retFunc,'returnFocusID':retFocus,
'loc':locTypes.NE,'type':contentTypes.alert,'task':sTask,
'title':'Alert!','alertType':g_jsErrorType,'alertText':g_jsErrorTxt
});
g_Alert[g_Aln].show();
g_Aln+=1;
}
function showMsgBox(id,sTitle,sQuestion,eType,retFunc,retFocus){
g_MsgBox=new ModalDlg({'id':id,
'width':300,'height':200,'returnFunc':retFunc,'returnFocusID':retFocus,
'loc':locTypes.CEN,'type':contentTypes.MsgBox,'task':'unknown',
'title':sTitle,'msgboxType':eType,'msgboxQuestion':sQuestion
});
g_MsgBox.show();
}
function showCsMsgBox(id,sTitle,sQuestion,eType,retFunc,retFocus){
g_MsgBox=new ModalDlg({'id':id,
'width':300,'height':200,'returnFunc':retFunc,'returnFocusID':retFocus,
'loc':locTypes.CEN,'type':contentTypes.MsgBox,'task':'unknown',
'title':sTitle,'msgboxType':eType,'msgboxQuestion':sQuestion
});
g_MsgBox.show();
}
function leftPanelKeyboardEvent(e)
{
var key;
if(document.all){key=event.keyCode;}
else{key=e.which;}
switch(key){
case 113:
try{top.OpenSearchDialog(SearchPage);}
catch(ex){alert("No Search Defined for screen");}
event.keyCode=0;
break;
case 114:
case 118:
event.keyCode=0;
break;
case 18:
pressed_keys=key;
break;
case 83:
pressed_keys=pressed_keys+""+key;
break;
}
if((key!=18)&&(key!=83)){
pressed_keys="";
}
if(pressed_keys!=""){
aux=new String(pressed_keys);
if((aux.indexOf('1883')!=-1)||(aux.indexOf('171899')!=-1)){
pressed_keys="";
}
}
}
function getHelp(e){top.wibHelp_Click();return false;}
addDOMLoadEvent(stdOnload);
edAddEvent(document,"keydown",leftPanelKeyboardEvent);
edAddEvent(document,"help",getHelp);
function ltrim(str,chars){
chars=chars||"\\s";
return str.replace(new RegExp("^["+chars+"]+","g"),"");
}
function rtrim(str,chars){
chars=chars||"\\s";
return str.replace(new RegExp("["+chars+"]+$","g"),"");
}
function trim(str,chars){
return ltrim(rtrim(str,chars),chars);
}
function setFocus(elementId,frameName){
var domElement=top.frames['ifMainContent']._gE(elementId);
if(domElement){
setTimeout(function(){try{domElement.focus();domElement.select();}catch(err){}},500);
}
}
function SetDialogTitle(){
var mainDoc=top._gE('ModalDialogs');
var foundDialogOpen=false;
if(mainDoc&&mainDoc!=undefined&&mainDoc!=null){
if(mainDoc.childNodes&&mainDoc.childNodes!=undefined&&mainDoc.childNodes!=null){
if(mainDoc.childNodes.length>0){
for(var index=0;index<mainDoc.childNodes.length;index++){
if(mainDoc.childNodes[index].style.display!='none'){
foundDialogOpen=true;
return;
}
}
}
}
}
}
function stdOnUnload(){
}
function ShowError(txtMessage,iType,callBackFunc){
top.g_jsErrorTxt=txtMessage;
top.g_jsErrorType=iType;
top.DisplayError(callBackFunc);
}
function ClearError(){
top.g_jsErrorType=null;
}
function fixMozillaItemScrolling(lbarID){
if(navigator.userAgent.toLowerCase().indexOf("mozilla")>=0){
if(navigator.userAgent.toLowerCase().indexOf("firefox")>=0){
ig.getElementById(lbarID+"_Items_0").parentNode.style.height=0;
}
}
}
function hideSelectBoxes(myDoc){
for(var i=0;i<myDoc.forms.length;i++){
for(var e=0;e<myDoc.forms[i].length;e++){
if(myDoc.forms[i].elements[e].tagName=="SELECT"){
myDoc.forms[i].elements[e].style.visibility="hidden";
}
}
}
}
function displaySelectBoxes(myDoc){
for(var i=0;i<myDoc.forms.length;i++){
for(var e=0;e<myDoc.forms[i].length;e++){
if(myDoc.forms[i].elements[e].tagName=="SELECT"){
myDoc.forms[i].elements[e].style.visibility="visible";
}
}
}
}
function ComboSetIndex(iIndex,sCombo){
var combo=igcmbo_getComboById(sCombo);
combo.setSelectedIndex(iIndex);
if(iIndex==-1){
combo.editable=true;
combo.setValue('');
combo.editable=false;
}
}
function elemReadOnly(strClientId,blnDisabled){
var xGet=_gE(strClientId);
if(xGet!=null){
xGet.readOnly=blnDisabled;
}
}
function ReleaseEvents(){
var events=["focus","blur","change","click","mousedown",
"mouseup","mouseover","keypress","keydown",
"keyup","keypress"];
var helper=function(obj){
var i;
for(i=0;i<events.length;i++){
obj["on"+events[i]]=null;
}
for(i=0;i<parent.childNodes.length;i++){
helper(parent.childNodes[i]);
}
};
helper(document);
}
function CloneArray(_Arr){
var array=[];var iter=_Arr.length;if(iter>3){
var tVal=0;var n=iter%4;if(n>0){
do
{array[tVal]=_Arr[tVal];tVal++;}while(--n);
}n=parseInt(iter/4);do
{array[tVal]=_Arr[tVal];tVal++;array[tVal]=_Arr[tVal];tVal++;array[tVal]=_Arr[tVal];tVal++;array[tVal]=_Arr[tVal];tVal++;}while(--n);
}else
{for(var nX in _Arr){array[nX]=_Arr[nX];}}return array;
}